var express = require('express');
const { default: mongoose } = require('mongoose');
var router = express.Router();
const { planModel, zhouplanModel, riplanModel, yueplanModel,
	jiplanModel, bannianplanModel, gongzuonianplanModel,
	zhijieplanModel, gongzuoplanModel, xiashuplanModel, ri_reportModel, zhou_reportModel, yue_reportModel, ji_reportModel } = require('../model/mry_model')
router.get('/region', async (req, res) => {
	res.send({})
})
router.get('/plans', async (req, res) => {
	let riplan = await riplanModel.find({ status: '日计划' }).exec()
	let zhouplan = await zhouplanModel.find({ status: '周计划' }).exec()
	let yueplan = await yueplanModel.find({ status: '月计划' }).exec()
	let jiplan = await jiplanModel.find({ status: '半年计划' }).exec()
	let bannianplan = await bannianplanModel.find({ status: '半年工作计划' }).exec()
	let gongzuonianplan = await gongzuonianplanModel.find({ status: '工作年计划' }).exec()
	let zhijieplan = await zhijieplanModel.find({ status: '直接计划展示' }).exec()
	let gongzuoplan = await gongzuoplanModel.find({ status: '所有工作计划' }).exec()
	let xiashuplan = await xiashuplanModel.find({ status: '工作下属计划' }).exec()
	res.send({ riplan, zhouplan, yueplan, jiplan, bannianplan, gongzuonianplan, zhijieplan, gongzuoplan, xiashuplan })
})
router.get('/report', async (req, res) => {
	let rireport = await ri_reportModel.find({ status: '日计划' }).exec()

	res.send({ rireport })
})

router.get('/getplans', async (req, res) => {
	let data;
	let anutitle = req.query.anutitle
	let anutype = req.query.anutype
	let anustate = req.query.anustate
	let anutitlereg = new RegExp(anutitle, 'i')
	let searcharr = [];

	if (anutitle) {
		searcharr.push({ anutitle: anutitlereg })
	}
	if (anutype) {
		searcharr.push({ anutype })
	}
	if (anustate) {
		searcharr.push({ anustate })
	}
	if (searcharr.length > 0) {
		data = await planModel.find({ $and: searcharr })
	}
	else {
		data = await planModel.find()
	}
	res.send({
		data
	})
})


module.exports = router;